package com.tledu.collection;

import java.util.Objects;

public class Student implements Comparable<Student>{
//public class Student{
    /**
     * 学号
     */
    private Integer stuNum;
    private String name;

    public Student(Integer stuNum, String name) {
        this.stuNum = stuNum;
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getStuNum() {
        return stuNum;
    }

    public void setStuNum(Integer stuNum) {
        this.stuNum = stuNum;
    }

    /**
     * 用于判断两个对象是否相等
     * @param other
     * @return
     */
    @Override
    public boolean equals(Object other) {
        if (!(other instanceof Student)) {
            return false;
        }
        // 编写判断逻辑
        Student otherStu = (Student) other;
        return this.getStuNum().equals(otherStu.getStuNum());
    }

    @Override
    public int hashCode() {
        // 返回一个hash编码
        // 两个对象相等，hash一定是相等的
        // 为了有了equals还有有hasCode
        // 每次都执行equals性能比较差的，会先比较hash，如果hash不一致，就不进行后续的比较
        return Objects.hash(stuNum);
    }

    @Override
    public int compareTo(Student o) {
        return this.getStuNum() - o.getStuNum();
    }
}
